package com.taobao.tddl.tddl;

import com.taobao.tddl.BaseTest;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

/**
 * Created by qibaichao on 2015/5/21.
 */
public class TableCreate extends BaseTest {


    @Test
    public  void createTableSql() {

        StringBuilder sb = new StringBuilder();
        String dropTable = "DROP TABLE IF EXISTS ";
        String createTable = "CREATE TABLE  IF NOT EXISTS ";
        String tablePrefix = "tddl_";
        String tableName = "";

        String sql = "(   `id` int(32) NOT NULL auto_increment,\n" +
                "  `user_id` varchar(32) NOT NULL  ,\n" +
                "  `create_time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n" +
                "  `remark` varchar(32) ,\n" +
                "  PRIMARY KEY  (`id`)\n" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='tddl测试表';";

        int tableIndex = 0;
        for (int i = 0; i < 4; i++) {
            tableName = tablePrefix + StringUtils.leftPad("" + i, 2, "0");
            sb.append(dropTable + tableName + ";\n" + createTable + tableName).append(sql).append("\n");
        }

        System.out.println(sb);
    }

    @Test
    public  void dropTableSql() {
        StringBuilder sb = new StringBuilder();
        String dropTable = "DROP TABLE IF EXISTS ";
        String tablePrefix = "tddl_";
        String tableName = "";

        int tableIndex = 0;
        for (int i = 0; i < 4; i++) {
            tableName = tablePrefix + StringUtils.leftPad("" + i, 2, "0");
            sb.append(dropTable + tableName + ";\n");
        }

        System.out.println(sb);

    }


}
